package cn.zn.menu.dto;

import cn.hutool.core.collection.CollUtil;
import cn.zn.dept.entity.SysDept;
import cn.zn.menu.entity.SysMenu;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author zn-admin
 */
public class TreeSelectDto implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private String id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelectDto> children;

    public TreeSelectDto() {

    }

    public TreeSelectDto(SysDept dept) {
        this.id = dept.getId();
        this.label = dept.getName();
        this.children = dept.getChildren().stream().map(TreeSelectDto::new).collect(Collectors.toList());
    }

    public TreeSelectDto(SysMenu menu) {
        this.id = menu.getId();
        this.label = menu.getMenuName();
        if (CollUtil.isNotEmpty(menu.getChildren())) {
            this.children = menu.getChildren().stream().map(TreeSelectDto::new).collect(Collectors.toList());
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public List<TreeSelectDto> getChildren() {
        return children;
    }

    public void setChildren(List<TreeSelectDto> children) {
        this.children = children;
    }
}
